import requests
import re

"""
"headers":[{"name":"cf-alt-svc","value":"{}"},
{"name":"CF-Cache-Status","value":"DYNAMIC"},
{"name":"CF-RAY","value":"57e2289de74d8bba-SZX"},
{"name":"Connection","value":"keep-alive"},
{"name":"Content-Disposition","value":"attachment; filename=\"½­ÄÏÉÕ¾Æ4k¶¯Âþ±ÚÖ½_±Ë°¶Í¼Íø.jpg\""},
{"name":"Content-Length","value":"3869095"},{"name":"Content-Type","value":"image/jpg"},
{"name":"Date","value":"Fri, 03 Apr 2020 10:38:12 GMT"},{"name":"Server","value":"yunjiasu-nginx"},
{"name":"Set-Cookie","value":"zkhandownid21617=2; expires=Fri, 03-Apr-2020 10:41:12 GMT; Max-Age=180; path=/"}]},
"headers":[{"name":"Accept","value":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"},
{"name":"Accept-Encoding","value":"gzip, deflate"},
{"name":"Accept-Language","value":"zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2"},
{"name":"Connection","value":"keep-alive"},
{"name":"Cookie","value":"__cfduid=d7b6a08c3640815dfcaac3e582b3f3c751585811140; 
    Hm_lvt_14b14198b6e26157b7eba06b390ab763=1585811142; 
    Hm_lpvt_14b14198b6e26157b7eba06b390ab763=1585811142; 
    Hm_lvt_526caf4e20c21f06a4e9209712d6a20e=1585811151; 
    Hm_lpvt_526caf4e20c21f06a4e9209712d6a20e=1585909625; 
    PHPSESSID=331ttgv6si19ng0eadga33q6v5; 
    zkhanmlusername=qq987532158576; 
    zkhanmluserid=2966281; 
    zkhanmlgroupid=1; 
    zkhanmlrnd=wgfzlgtYuz2CtwBxnRXQ; 
    zkhanmlauth=dd3d2f4a9e7b43fa849d4c386fc331e3; 
    zkhandownid21617=1"},
{"name":"Host","value":"pic.netbian.com"},
{"name":"Referer","value":"http://pic.netbian.com/tupian/21617.html"},
{"name":"Upgrade-Insecure-Requests","value":"1"},
{"name":"User-Agent","value":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0"}]}}
"""

url = "http://pic.netbian.com/tupian/21617.html"
cookie="cfduid=d7b6a08c3640815dfcaac3e582b3f3c751585811140;" \
       "Hm_lvt_14b14198b6e26157b7eba06b390ab763=1585811142; " \
       "Hm_lpvt_14b14198b6e26157b7eba06b390ab763=1585811142; " \
       "Hm_lvt_526caf4e20c21f06a4e9209712d6a20e=1585811151; " \
       "Hm_lpvt_526caf4e20c21f06a4e9209712d6a20e=1585909625; " \
       "PHPSESSID=331ttgv6si19ng0eadga33q6v5; " \
       "zkhanmlusername=qq987532158576;zkhanmluserid=2966281; " \
       "zkhanmlgroupid=1;zkhanmlrnd=wgfzlgtYuz2CtwBxnRXQ; " \
       "zkhanmlauth=dd3d2f4a9e7b43fa849d4c386fc331e3; zkhandownid21617=1"
headers:"Upgrade-Insecure-Requests: 1"
for i in range(3):
    pn=i*30
    img_url=url.format(pn)
    res = requests.get(img_url)
    data = res.text
    img_urls = re.findall(r'thumbURL":"(.*?)"', data)
    for index, img_url in enumerate(img_urls):
        print(index+i*30)
        res = requests.get(img_url)
        suffix = img_url.split(".")[-1]  # 拿文件后缀格式

        imgname = "emotion/img" + str(index) + str(i*30) + "." + suffix
        with open(imgname, "wb") as f:
            f.write(res.content)
print("ok")